<!DOCTYPE html>
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>商品管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
	<script src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.min.js"></script>

	<!--bootstrap-toastr-->
	<script type="text/javascript" src="/bootstrap/toastr/toastr.min.js"></script>
	<link rel="stylesheet" type="text/css" href="/bootstrap/toastr/toastr.css">
	<script>
		$(function () {
			getListGoods();
		});
		function getListGoods() {
			$.ajax({
				url : "/goods/getListGoods",
				dataType : "json",
				type : "post",
				data : {pageNumber : $("#pageNumber").val(),goodsName : $("#goodsName").val()},
				success : function (returnData) {

					var result = returnData.data.list;
					var table = '';
					for (var i = 0; i < result.length; i++) {
						table += '<tr>'
						table += '<td><input name="box" value="'+ result[i].id +'" type="checkbox" ></td>'
						table += '<td>'+ result[i].id +'</td>'
						table += '<td>'+ result[i].goodsName +'</td>'
						table += '<td>'+ result[i].price +'</td>'
						table += '<td>'+ result[i].category1Name +'</td>'
						table += '<td>'+ result[i].category2Name +'</td>'
						table += '<td>'+ result[i].category3Name +'</td>'
						if (result[i].auditStatus == 0){
							table += '<td>'+ "未申请" +'</td>'
						}else if (result[i].auditStatus == 1){
							table += '<td>'+ "申请中" +'</td>'
						}else if (result[i].auditStatus == 2){
							table += '<td>'+ "申请通过" +'</td>'
						}else if (result[i].auditStatus == 3){
							table += '<td>'+ "审核驳回" +'</td>'
						}
						table += "</tr>"
					}

					$("#goodsTable").html(table);

					$("#showCount").html(returnData.data.total)
					$("#showPage").html(returnData.data.pages)

					$("#totalPage").val(returnData.data.pages)
					$("#totalCount").val(returnData.data.total)
					$("#pageNumber").val(returnData.data.pageNumer)

					var rowPages = ""
					for (var j = 1;j <= returnData.data.pages;j++){
						rowPages += "<li>"
						rowPages += "<a href='javascript:changePageNumber("+ j +")'>"+ j +"</a>"
						rowPages += "</li>"
						$("#pages").html(rowPages)
					}
				},
				error : function (returnData) {
					toastr.error(returnData.message)
				}
			})
		}

		function getPage(flag) {
			var pageNumber = parseInt($("#pageNumber").val());
			var totalPage = parseInt($("#totalPage").val());

			if (flag == 1){
				if (pageNumber <= 1){
					toastr.warning("已经是第一页");
					return;
				}
				$("#pageNumber").val(1);
			}else if (flag == 2) {
				if (pageNumber <= 1){
					toastr.warning("已经是第一页");
					return;
				}
				$("#pageNumber").val(pageNumber - 1);
			}else if (flag == 3){
				if (pageNumber >= totalPage){
					toastr.warning("已经是最后一页");
					return;
				}
				$("#pageNumber").val(pageNumber + 1);
			} else if (flag == 4) {
				if (pageNumber >= totalPage){
					toastr.warning("已经是最后一页");
					return;
				}
				$("#pageNumber").val(totalPage);
			}
			getListGoods();
		}

		function changePageNumber(obj) {
			$("#pageNumber").val(obj);
			getListGoods();
		}

		function reload() {
			window.location.reload();
		}
		
		function updateAuditOk(o) {
			var names = $("[name=box]:checked");
			var ids = [];
			$(names).each(function (i, e) {
				ids.push(e.value)
			});
			if (ids <= 0) {
				toastr.warning("请选择要审核的商品")
				return;
			}
			if (confirm("确定要修改该商品的审核吗?")) {
				$.ajax({
					url : "/goods/updateGoodsAuditStatus",
					type : "post",
					data : {ids : ids,auditStatus:o},
					dataType : "json",
					success : function (returnData) {
						if (returnData.code == 200) {
							toastr.success(returnData.message);
						} else {
							toastr.error(returnData.message);
						}
						setTimeout(function(){
									reload();
								},500
						);

					},
					error : function (returnData) {
						alert(returnData.message);
					}
				});
			} else {
				return;
			}
		}
	</script>

</head>

<body class="hold-transition skin-red sidebar-mini" >
  <!-- .box-body -->
                
                    <div class="box-header with-border">
                        <h3 class="box-title">商品审核</h3>
                    </div>

                    <div class="box-body">

                        <!-- 数据表格 -->
                        <div class="table-box">

                            <!--工具栏-->
                            <div class="pull-left">
                                <div class="form-group form-inline">
                                    <div class="btn-group">
                                        <button type="button" class="btn btn-default" title="删除" ><i class="fa fa-trash-o"></i> 删除</button>
                                        <button type="button" class="btn btn-default" title="审核通过" onclick="updateAuditOk(2)"><i class="fa fa-check"></i> 审核通过</button>
                                        <button type="button" class="btn btn-default" title="驳回" onclick="updateAuditOk(3)"><i class="fa fa-ban"></i> 驳回</button>
                                        <button type="button" class="btn btn-default" onclick="reload()" title="刷新" ><i class="fa fa-refresh"></i> 刷新</button>
                                    </div>
                                </div>
                            </div>
                            <div class="box-tools pull-right">
                                <div class="has-feedback">
                                    商品名称：<input id="goodsName">
									<button class="btn btn-default" onclick="getListGoods()" >查询</button>
                                </div>
                            </div>
                            <!--工具栏/-->

			                  <!--数据列表-->
			                  <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
			                      <thead>
			                          <tr>
			                              <th class="" style="padding-right:0px">
			                                  <input id="selall" type="checkbox" class="icheckbox_square-blue">
			                              </th> 
										  <th class="sorting_asc">商品ID</th>
									      <th class="sorting">商品名称</th>
									      <th class="sorting">商品价格</th>
									      <th class="sorting">一级分类</th>
									      <th class="sorting">二级分类</th>
									      <th class="sorting">三级分类</th>
									      <th class="sorting">状态</th>									     						
			                          </tr>
			                      </thead>
			                      <tbody id="goodsTable">

			                      </tbody>
			                  </table>
			                  <!--数据列表/-->
							<div align="center">
								<nav aria-label="Page navigation">
									<input type="hidden" id="pageNumber" name="pageNumber">
									<input type="hidden" id="totalPage">
									<div class="page_num_inf">
										<i></i> 共
										<span id="showPage"></span>页<span id="showCount"></span>条
									</div>
									<ul class="pagination">
										<li>
											<a href="javascript:getPage(1);" aria-label="Previous">
												<span aria-hidden="true">首页</span>
											</a>

											<a href="javascript:getPage(2);" aria-label="Previous">
												<span aria-hidden="true">&laquo;上一页</span>
											</a>
										</li>
									</ul>
									<ul class="pagination" id="pages">

									</ul>
									<ul class="pagination">
										<li>
											<a href="javascript:getPage(3);" aria-label="Next">
												<span aria-hidden="true">下一页&raquo;</span>
											</a>
											<a href="javascript:getPage(4);" aria-label="Previous">
												<span aria-hidden="true">尾页</span>
											</a>
										</li>
									</ul>
								</nav>
							</div>


						</div>
                        <!-- 数据表格 /-->
                        
                        
                     </div>
                    <!-- /.box-body -->
        
</body>

</html>